{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "from transformers import BertTokenizer, BertConfig\n",
    "from transformers import BertModel\n",
    "import nltk\n",
    "import numpy as np\n",
    "import torch\n",
    "import re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'),\n",
       " PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tf.config.list_physical_devices()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "def is_available_in_pos_list(dict_list, begin_pos, end_pos):\n",
    "    for entry in dict_list:\n",
    "        if((entry[\"start\"]<=begin_pos and entry[\"end\"]>begin_pos) or ((entry[\"start\"]<end_pos and entry[\"end\"]>=end_pos))):\n",
    "            return True\n",
    "    \n",
    "    return False\n",
    "'''\n",
    "def get_bert_token_positions(input_text,token_list,start_from_pos=0,):\n",
    "    \n",
    "    pos_list = []                    \n",
    "    \n",
    "    name_to_match = input_text.lower().replace(\" \",\"\")\n",
    "    remaining_name = input_text.lower().replace(\" \",\"\")\n",
    "    \n",
    "    name = \"\"\n",
    "    count = start_from_pos\n",
    "\n",
    "    for entry in token_list[start_from_pos:]:\n",
    "        if(remaining_name.startswith(entry.strip(\"##\").lower())):\n",
    "            pos_list.append(count)\n",
    "            remaining_name = remaining_name[len(entry.strip(\"##\").lower()):]\n",
    "            name = name + entry.strip(\"##\").lower()\n",
    "            if(name == name_to_match):\n",
    "                break\n",
    "        else:\n",
    "            pos_list = []\n",
    "            name = \"\"\n",
    "            remaining_name = name_to_match\n",
    "            if(remaining_name.startswith(entry.strip(\"##\").lower())):                                 \n",
    "                pos_list.append(count)                                                                \n",
    "                remaining_name = remaining_name[len(entry.strip(\"##\").lower()):]\n",
    "                name = name + entry.strip(\"##\").lower()    \n",
    "                if(name == name_to_match):                                   \n",
    "                    break\n",
    "\n",
    "        count = count + 1\n",
    "\n",
    "    return pos_list\n",
    "'''\n",
    "def get_bert_token_positions(input_text,token_list,start_from_pos=0,prior_partial_word=\"\"):\n",
    "    partial_word = \"\"\n",
    "\n",
    "    pos_list = []                    \n",
    "    \n",
    "    if(prior_partial_word!=\"\"):\n",
    "        input_text = prior_partial_word + input_text \n",
    "\n",
    "    name_to_match = input_text.lower().replace(\" \",\"\")\n",
    "    remaining_name = input_text.lower().replace(\" \",\"\")\n",
    "    \n",
    "    name = \"\"\n",
    "    count = start_from_pos\n",
    "\n",
    "    for entry in token_list[start_from_pos:]:\n",
    "        entry_text = entry.strip(\"##\").lower()\n",
    "        if(entry_text.startswith(remaining_name) and (entry_text != remaining_name)):\n",
    "            partial_word = remaining_name\n",
    "            pos_list.append(count)\n",
    "            break\n",
    "             \n",
    "        if(remaining_name.startswith(entry_text)):\n",
    "            pos_list.append(count)\n",
    "            remaining_name = remaining_name[len(entry_text):]\n",
    "            name = name + entry_text\n",
    "            if(name == name_to_match):\n",
    "                break\n",
    "        else:\n",
    "            pos_list = []\n",
    "            name = \"\"\n",
    "            remaining_name = name_to_match\n",
    "            if(remaining_name.startswith(entry.strip(\"##\").lower())):                                 \n",
    "                pos_list.append(count)                                                                \n",
    "                remaining_name = remaining_name[len(entry.strip(\"##\").lower()):]\n",
    "                name = name + entry.strip(\"##\").lower()    \n",
    "                if(name == name_to_match):                                   \n",
    "                    break\n",
    "\n",
    "        count = count + 1\n",
    "    \n",
    "    return [pos_list,partial_word]\n",
    "\n",
    "def process_string(string_input, entity_list):\n",
    "    string_input = re.sub(r'Admission Date :\\n([0-9/ ]*)\\n', 'Admission Date : \\g<1>\\n', string_input)\n",
    "    string_input = re.sub(r'Discharge Date :\\n([0-9/ ]*)\\n', 'Discharge Date : \\g<1>\\n', string_input)\n",
    "    \n",
    "    \n",
    "    tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')\n",
    "    init_sentences = tokenizer.tokenize(string_input)\n",
    "    \n",
    "    sentences = []\n",
    "    \n",
    "    for entry in init_sentences:\n",
    "        sentences.extend(entry.split(\"\\n\"))\n",
    "    \n",
    "    #config = BertConfig.from_pretrained('C:/Users/itsma/Documents/BERT_models/NCBI_BERT_pubmed_mimic_uncased_L-12_H-768_A-12')\n",
    "    #config.output_hidden_states = True\n",
    "\n",
    "    bert_tokenizer = BertTokenizer.from_pretrained('C:/Users/itsma/Documents/BERT_models/NCBI_BERT_pubmed_mimic_uncased_L-12_H-768_A-12')\n",
    "    #bert_model = BertModel.from_pretrained(\"C:/Users/itsma/Documents/BERT_models/NCBI_BERT_pubmed_mimic_uncased_L-12_H-768_A-12\",config=config)\n",
    "    \n",
    "    positions_covered = 0\n",
    "    sentence_list = []\n",
    "    \n",
    "    for index in range(len(sentences)):\n",
    "        new_dict_sentence = {}\n",
    "        sentence = sentences[index]\n",
    "        new_dict_sentence[\"sentence\"] = sentence\n",
    "        #new_dict_sentence[\"padding_length\"] = padding_length\n",
    "        #start_index_bert = max(0,index-padding_length)\n",
    "        #end_index_bert = min(len(sentences),index+padding_length)\n",
    "\n",
    "        bert_input = sentences[index]\n",
    "        \n",
    "        encodings = bert_tokenizer.encode(bert_input,add_special_tokens = True)\n",
    "        new_dict_sentence[\"encodings\"] = encodings\n",
    "        input_ids = torch.tensor(encodings).unsqueeze(0)  \n",
    "        #outputs = bert_model(input_ids)\n",
    "        #bert_vector = outputs[2]\n",
    "        bert_tokens = bert_tokenizer.convert_ids_to_tokens(encodings) #bert_tokenizer.tokenize(bert_input,add_special_tokens = True)\n",
    "        new_dict_sentence[\"tokens\"] = bert_tokens\n",
    "        \n",
    "        start_pos = 0\n",
    "        #prior_pos = get_bert_token_positions(' '.join(sentences[start_index_bert:index]),bert_tokens)\n",
    "        \n",
    "        #if(len(prior_pos)>0):\n",
    "            #start_pos = max(prior_pos)\n",
    "            \n",
    "        tokens = nltk.word_tokenize(sentence)\n",
    "        pos_tokens = nltk.pos_tag(tokens)\n",
    "\n",
    "        sentence_covered = ''\n",
    "        prior_partial_word = ''\n",
    "        label_list = [0] * len(encodings)\n",
    "        \n",
    "        for token in pos_tokens:\n",
    "            new_dict = {}\n",
    "            current_word = token[0]\n",
    "            \n",
    "            [bert_token_positions, partial_word] = get_bert_token_positions(current_word,bert_tokens,start_pos,prior_partial_word)\n",
    "            \n",
    "            #ec_list_layers = []\n",
    "            \n",
    "            if(len(bert_token_positions)==0):\n",
    "                prior_partial_word = \"\"\n",
    "                continue\n",
    "            if(partial_word != \"\"):\n",
    "                prior_partial_word = partial_word\n",
    "                start_pos = bert_token_positions[-1]\n",
    "            else:\n",
    "                prior_partial_word = \"\"\n",
    "                start_pos = bert_token_positions[-1] + 1\n",
    "            token_position = string_input.find(current_word, positions_covered)\n",
    "            spaces_between = string_input[positions_covered:token_position] \n",
    "            sentence_covered = sentence_covered + spaces_between + current_word\n",
    "            positions_covered = token_position + len(current_word)\n",
    "            begin_pos = token_position\n",
    "            end_pos = positions_covered\n",
    "            #bert_token_positions = get_bert_token_positions(current_word,bert_tokens,start_pos)[0]\n",
    "           \n",
    "            '''\n",
    "            vec_list_layers = []\n",
    "            \n",
    "            if(len(bert_token_positions)==0):\n",
    "                continue\n",
    "            start_pos = bert_token_positions[-1] + 1\n",
    "            '''\n",
    "            entity_index=1\n",
    "            for entity in entity_list:\n",
    "                if(is_available_in_pos_list(entity,begin_pos,end_pos)):\n",
    "                    for entry in bert_token_positions:\n",
    "                        label_list[entry] = entity_index\n",
    "                \n",
    "                entity_index = entity_index + 1\n",
    "                \n",
    "                \n",
    "        new_dict_sentence[\"labels\"] = label_list\n",
    "\n",
    "        sentence_list.append(new_dict_sentence)\n",
    "        \n",
    "    return sentence_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "class DischargeNote():\n",
    "    def __init__(self, root,padding_length=0):\n",
    "        self.xml_root = root\n",
    "        self.padding_length = padding_length\n",
    "        \n",
    "    def process_note(self):\n",
    "        root = self.xml_root\n",
    "        text_section = root.find('TEXT')\n",
    "        text = text_section.text\n",
    "        \n",
    "        tag_section = root.find('TAGS')\n",
    "        event_list = []\n",
    "        timex_list = []\n",
    "        tlink_list = []\n",
    "        sectime_list = []\n",
    "        for child in tag_section:\n",
    "            if(child.tag=='EVENT'):\n",
    "                event_list.append(child.attrib)\n",
    "            elif(child.tag=='TIMEX3'):\n",
    "                timex_list.append(child.attrib)\n",
    "            elif(child.tag=='TLINK'):\n",
    "                tlink_list.append(child.attrib)\n",
    "            elif(child.tag=='SECTIME'):\n",
    "                sectime_list.append(child.attrib)\n",
    "        \n",
    "        event_list_new = []\n",
    "        \n",
    "        for sub in event_list:\n",
    "            new_dict = {}\n",
    "            new_dict[\"start\"] = int(sub[\"start\"])\n",
    "            new_dict[\"end\"] = int(sub[\"end\"])\n",
    "            event_list_new.append(new_dict)\n",
    "        \n",
    "        event_list_new = sorted(event_list_new, key = lambda i: i['start'])\n",
    "        \n",
    "        timex_list_new = []\n",
    "        \n",
    "        for sub in timex_list:\n",
    "            new_dict = {}\n",
    "            new_dict[\"start\"] = int(sub[\"start\"])\n",
    "            new_dict[\"end\"] = int(sub[\"end\"])\n",
    "            timex_list_new.append(new_dict)\n",
    "        \n",
    "        timex_list_new = sorted(timex_list_new, key = lambda i: i['start'])\n",
    "        \n",
    "        entity_list = []\n",
    "        entity_list.append(event_list_new)\n",
    "        entity_list.append(timex_list_new)\n",
    "        \n",
    "        \n",
    "        self.processed_text = process_string(text,entity_list)\n",
    "        \n",
    "        sentences_length = len(self.processed_text)\n",
    "        encoding_list = []\n",
    "        label_list = []\n",
    "        token_list = []\n",
    "        \n",
    "        for sentence_index in range(sentences_length):\n",
    "            padding_unsuccess = True\n",
    "            padding_length = self.padding_length\n",
    "            \n",
    "            encodings = []\n",
    "            labels = []\n",
    "            tokens = []\n",
    "            while(padding_unsuccess):\n",
    "                encodings = []\n",
    "                labels = []\n",
    "                tokens=[]\n",
    "                \n",
    "                begin_index = max(0,sentence_index-padding_length)\n",
    "                end_index = min(sentences_length,sentence_index+padding_length)\n",
    "                current_index = 1\n",
    "                last_index = end_index - begin_index + 1\n",
    "        \n",
    "                if(begin_index==end_index):\n",
    "                    entry = self.processed_text[begin_index]\n",
    "                    encodings.extend(entry['encodings'])\n",
    "                    tokens.extend(entry['tokens'])\n",
    "                    labels.extend(entry['labels'])\n",
    "                else:\n",
    "                    for entry in self.processed_text[begin_index:end_index+1]:\n",
    "                        if(current_index==1):\n",
    "                            encodings.extend(entry['encodings'][:-1])\n",
    "                            tokens.extend(entry['tokens'][:-1])\n",
    "                            labels.extend(entry['labels'][:-1])\n",
    "                        elif(current_index==last_index):\n",
    "                            encodings.extend(entry['encodings'][1:])\n",
    "                            tokens.extend(entry['tokens'][1:])\n",
    "                            labels.extend(entry['labels'][1:])\n",
    "                        else:\n",
    "                            encodings.extend(entry['encodings'][1:-1])\n",
    "                            tokens.extend(entry['tokens'][1:-1])\n",
    "                            labels.extend(entry['labels'][1:-1])\n",
    "                        current_index = current_index + 1\n",
    "\n",
    "                if(len(encodings)<=512):\n",
    "                    padding_unsuccess = False\n",
    "                else:\n",
    "                    padding_length = max(0,padding_length - 1)\n",
    "            \n",
    "            encoding_list.append(encodings)\n",
    "            token_list.append(tokens)\n",
    "            label_list.append(labels)\n",
    "            \n",
    "        return [encoding_list,token_list,label_list]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import xml.etree.ElementTree as ET"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "file = \"1.xml\"\n",
    "\n",
    "file_name = os.path.join(\"C:/Users/itsma/Documents/Capstone project/DS5500-capstone/train_data/\", file)\n",
    "tree = ET.parse(file_name)\n",
    "root = tree.getroot()\n",
    "discharge_note = DischargeNote(root,1)\n",
    "results = discharge_note.process_note()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[101, 9634, 3058, 1024, 5641, 1013, 2756, 1013, 2857, 11889, 3058, 1024, 2184, 1013, 5840, 1013, 2857, 102]\n"
     ]
    }
   ],
   "source": [
    "print(results[0][1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['[CLS]', 'admission', 'date', ':', '09', '/', '29', '/', '1993', 'discharge', 'date', ':', '10', '/', '04', '/', '1993', '[SEP]']\n"
     ]
    }
   ],
   "source": [
    "print(results[1][1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 0, 0, 2, 2, 2, 2, 2, 1, 0, 0, 2, 2, 2, 2, 2, 0]\n"
     ]
    }
   ],
   "source": [
    "print(results[2][1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'sentences' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-76-5149386e30ff>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[1;31m# For every sentence...\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[1;32mfor\u001b[0m \u001b[0msent\u001b[0m \u001b[1;32min\u001b[0m \u001b[0msentences\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      6\u001b[0m     \u001b[1;31m# `encode` will:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      7\u001b[0m     \u001b[1;31m#   (1) Tokenize the sentence.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'sentences' is not defined"
     ]
    }
   ],
   "source": [
    "# Tokenize all of the sentences and map the tokens to thier word IDs.\n",
    "input_ids = []\n",
    "\n",
    "# For every sentence...\n",
    "for sent in sentences:\n",
    "    # `encode` will:\n",
    "    #   (1) Tokenize the sentence.\n",
    "    #   (2) Prepend the `[CLS]` token to the start.\n",
    "    #   (3) Append the `[SEP]` token to the end.\n",
    "    #   (4) Map tokens to their IDs.\n",
    "    encoded_sent = tokenizer.encode(\n",
    "                        sent,                      # Sentence to encode.\n",
    "                        add_special_tokens = True, # Add '[CLS]' and '[SEP]'\n",
    "\n",
    "                        # This function also supports truncation and conversion\n",
    "                        # to pytorch tensors, but we need to do padding, so we\n",
    "                        # can't use these features :( .\n",
    "                        #max_length = 128,          # Truncate all sentences.\n",
    "                        #return_tensors = 'pt',     # Return pytorch tensors.\n",
    "                   )\n",
    "    \n",
    "    # Add the encoded sentence to the list.\n",
    "    input_ids.append(encoded_sent)\n",
    "\n",
    "# Print sentence 0, now as a list of IDs.\n",
    "print('Original: ', sentences[0])\n",
    "print('Token IDs:', input_ids[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [],
   "source": [
    "from progressbar import ProgressBar\n",
    "pbar = ProgressBar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100% |########################################################################|\n"
     ]
    }
   ],
   "source": [
    "input_ids = []\n",
    "labels = []\n",
    "\n",
    "for file in pbar(os.listdir(\"C:/Users/itsma/Documents/Capstone project/DS5500-capstone/train_data/\")):\n",
    "    if file.endswith(\".xml\"):\n",
    "        file_name = os.path.join(\"C:/Users/itsma/Documents/Capstone project/DS5500-capstone/train_data/\", file)\n",
    "        tree = ET.parse(file_name)\n",
    "        root = tree.getroot()\n",
    "        discharge_note = DischargeNote(root,1)\n",
    "        results = discharge_note.process_note()\n",
    "        \n",
    "        sample_length = len(results[0])\n",
    "        \n",
    "        for index in range(sample_length):\n",
    "            input_ids.append(results[0][index])\n",
    "            labels.append(results[2][index])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pickle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [],
   "source": [
    "pickle.dump(input_ids,open(\"C:/Users/itsma/Documents/input_ids.pkl\",\"wb\"))\n",
    "pickle.dump(labels,open(\"C:/Users/itsma/Documents/label.pkl\",\"wb\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "config = BertConfig.from_pretrained('C:/Users/itsma/Documents/BERT_models/NCBI_BERT_pubmed_mimic_uncased_L-12_H-768_A-12')\n",
    "config.output_hidden_states = True\n",
    "\n",
    "bert_tokenizer = BertTokenizer.from_pretrained('C:/Users/itsma/Documents/BERT_models/NCBI_BERT_pubmed_mimic_uncased_L-12_H-768_A-12')\n",
    "bert_model = BertModel.from_pretrained(\"C:/Users/itsma/Documents/BERT_models/NCBI_BERT_pubmed_mimic_uncased_L-12_H-768_A-12\",config=config)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "bert_input1 = \"I love my Dog.He is Cute.\" \n",
    "bert_input2 = \"He is Cute.\"\n",
    "encodings1 = bert_tokenizer.encode(bert_input1,add_special_tokens = True)\n",
    "input_ids1 = torch.tensor(encodings1).unsqueeze(0)  \n",
    "encodings2 = bert_tokenizer.encode(bert_input2,add_special_tokens = True)\n",
    "input_ids2 = torch.tensor(encodings2).unsqueeze(0) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[  101,  1045,  2293,  2026,  3899,  1012,  2002,  2003, 10140,  1012,\n",
       "           102]])"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input_ids1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[101, 1045, 2293, 2026, 3899, 1012, 2002, 2003, 10140, 1012, 102]"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "encodings1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[  101,  2002,  2003, 10140,  1012,   102]])"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input_ids2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 0, 0, 0, 0, 0, 0, 0]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "[0] * 4 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {},
   "outputs": [],
   "source": [
    "sample_list = [1,2,3,4,5,6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 135,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sample_list[:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
